package j2metris.util;

/**
 * The LoopingList follows the same basic behavior as an <code>enum</code>, but
 * with a set of objects instead of integers. The list can be iterated through
 * at any interval, positive or negative, and, as its name suggests, will loop
 * around every time it reaches the end. It can give the currently selected
 * object as well as an object any distance away from the currently selected
 * object.
 */
public class LoopingList
{
    private int currentPosition;
    private final Object[] list;

    public LoopingList(Object[] objects, int initialPosition)
    {
        list = objects;
        currentPosition = LoopingModulo.calculate(
                initialPosition, list.length);
    }

    public LoopingList(Object[] objects)
    {
        this(objects, 0);
    }

    public void increment(int valueByWhichToIncrement)
    {
        currentPosition = LoopingModulo.calculate(currentPosition + 
                valueByWhichToIncrement, list.length);
    }

    public Object getObject(int increment)
    {
        increment = LoopingModulo.calculate(
                currentPosition + increment, list.length);
        return list[increment];
    }

    public Object getCurrentObject()
    {
        return list[currentPosition];
    }

    public int getCurrentPosition()
    {
        return currentPosition;
    }
}
